package com.hzx.ssm.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    //    配置Swagger的Docket实例
    @Bean
    public Docket docket() {
        //添加head参数配置start
        ParameterBuilder tokenPar1 = new ParameterBuilder();
        ParameterBuilder tokenPar2 = new ParameterBuilder();
        List<Parameter> pars = new ArrayList<>();
        tokenPar1.name("Admintoken").description("管理员令牌").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
        tokenPar2.name("Usertoken").description("用户令牌").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
        pars.add(tokenPar1.build());
        pars.add(tokenPar2.build());
        //添加head参数配置end

        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.hzx.ssm.controller"))
                .build()
                .globalOperationParameters(pars)
                .apiInfo(apiInfo());
    }

    private ApiInfo apiInfo() {

//        作者信息
        Contact contact = new Contact("郭培准",
                "https://www.cnblogs.com/panbingwen/p/11067746.html",
                "510191962@qq.com");

        return new ApiInfo(
                "表白墙的Swagger文档",
                "作者-郭培准",
                "1.0",
                "https://www.cnblogs.com/panbingwen/p/11067746.html",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
    }

}
